home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 21 / Cream of the Crop 21 (Terry Blount) (October 1996).iso / doom / qplus10.zip / TRIGGERS.QC < prev    next >
Text File  |  1996-08-18  |  14KB  |  645 lines

  1.  
  2. entity stemp, otemp, s, old;
  3.  
  4.  
  5. void() trigger_reactivate =
  6. {
  7.     self.solid = SOLID_TRIGGER;
  8. };
  9.  
  10. //=============================================================================
  11.  
  12. float    SPAWNFLAG_NOMESSAGE = 1;
  13. float    SPAWNFLAG_NOTOUCH = 1;
  14.  
  15. // the wait time has passed, so set back up for another activation
  16. void() multi_wait =
  17. {
  18.     if (self.max_health)
  19.     {
  20.         self.health = self.max_health;
  21.         self.takedamage = DAMAGE_YES;
  22.         self.solid = SOLID_BBOX;
  23.         self.flags = FL_OBJECT;            //ws        
  24.     }
  25. };
  26.  
  27.  
  28. // the trigger was just touched/killed/used
  29. // self.enemy should be set to the activator so it can be held through a delay
  30. // so wait for the delay time before firing
  31. void() multi_trigger =
  32. {
  33.     if (self.nextthink > time)
  34.     {
  35.         return;        // allready been triggered
  36.     }
  37.  
  38.     if (self.classname == "trigger_secret")
  39.     {
  40.         if (self.enemy.classname != "player")
  41.             return;
  42.         found_secrets = found_secrets + 1;
  43.         WriteByte (MSG_ALL, SVC_FOUNDSECRET);
  44.     }
  45.  
  46.     if (self.noise)
  47.         sound (self, CHAN_VOICE, self.noise, 1, ATTN_NORM);
  48.  
  49. // don't trigger again until reset
  50.     self.takedamage = DAMAGE_NO;
  51.  
  52.     activator = self.enemy;
  53.     
  54.     SUB_UseTargets();
  55.  
  56.     if (self.wait > 0)    
  57.     {
  58.         self.think = multi_wait;
  59.         self.nextthink = time + self.wait;
  60.     }
  61.     else
  62.     {    // we can't just remove (self) here, because this is a touch function
  63.         // called wheil C code is looping through area links...
  64.         self.touch = SUB_Null;
  65.         self.nextthink = time + 0.1;
  66.         self.think = SUB_Remove;
  67.     }
  68. };
  69.  
  70. void() multi_killed =
  71. {
  72.     self.enemy = damage_attacker;
  73.     multi_trigger();
  74. };
  75.  
  76. void() multi_use =
  77. {
  78.     self.enemy = activator;
  79.     multi_trigger();
  80. };
  81.  
  82. void() multi_touch =
  83. {
  84.     if (other.classname != "player")
  85.         return;
  86.     
  87. // if the trigger has an angles field, check player's facing direction
  88.     if (self.movedir != '0 0 0')
  89.     {
  90.         makevectors (other.angles);
  91.         if (v_forward * self.movedir < 0)
  92.             return;        // not facing the right way
  93.     }
  94.     
  95.     self.enemy = other;
  96.     multi_trigger ();
  97. };
  98.  
  99. /*QUAKED trigger_multiple (.5 .5 .5) ? notouch
  100. Variable sized repeatable trigger.  Must be targeted at one or more entities.  If "health" is set, the trigger must be killed to activate each time.
  101. If "delay" is set, the trigger waits some time after activating before firing.
  102. "wait" : Seconds between triggerings. (.2 default)
  103. If notouch is set, the trigger is only fired by other entities, not by touching.
  104. NOTOUCH has been obsoleted by trigger_relay!
  105. sounds
  106. 1)    secret
  107. 2)    beep beep
  108. 3)    large switch
  109. 4)
  110. set "message" to text string
  111. */
  112. void() trigger_multiple =
  113. {
  114.     if (self.sounds == 1)
  115.     {
  116.         precache_sound ("misc/secret.wav");
  117.         self.noise = "misc/secret.wav";
  118.     }
  119.     else if (self.sounds == 2)
  120.     {
  121.         precache_sound ("misc/talk.wav");
  122.         self.noise = "misc/talk.wav";
  123.     }
  124.     else if (self.sounds == 3)
  125.     {
  126.         precache_sound ("misc/trigger1.wav");
  127.         self.noise = "misc/trigger1.wav";
  128.     }
  129.     
  130.     if (!self.wait)
  131.         self.wait = 0.2;
  132.     self.use = multi_use;
  133.  
  134.     InitTrigger ();
  135.  
  136.     if (self.health)
  137.     {
  138.         if (self.spawnflags & SPAWNFLAG_NOTOUCH)
  139.             objerror ("health and notouch don't make sense\n");
  140.         self.max_health = self.health;
  141.         self.th_die = multi_killed;
  142.         self.takedamage = DAMAGE_YES;
  143.         self.solid = SOLID_BBOX;
  144.         self.flags = FL_OBJECT;            //ws
  145.         setorigin (self, self.origin);    // make sure it links into the world
  146.     }
  147.     else
  148.     {
  149.         if ( !(self.spawnflags & SPAWNFLAG_NOTOUCH) )
  150.         {
  151.             self.touch = multi_touch;
  152.         }
  153.     }
  154. };
  155.  
  156.  
  157. /*QUAKED trigger_once (.5 .5 .5) ? notouch
  158. Variable sized trigger. Triggers once, then removes itself.  You must set the key "target" to the name of another object in the level that has a matching
  159. "targetname".  If "health" is set, the trigger must be killed to activate.
  160. If notouch is set, the trigger is only fired by other entities, not by touching.
  161. if "killtarget" is set, any objects that have a matching "target" will be removed when the trigger is fired.
  162. if "angle" is set, the trigger will only fire when someone is facing the direction of the angle.  Use "360" for an angle of 0.
  163. sounds
  164. 1)    secret
  165. 2)    beep beep
  166. 3)    large switch
  167. 4)
  168. set "message" to text string
  169. */
  170. void() trigger_once =
  171. {
  172.     self.wait = -1;
  173.     trigger_multiple();
  174. };
  175.  
  176. //=============================================================================
  177.  
  178. /*QUAKED trigger_relay (.5 .5 .5) (-8 -8 -8) (8 8 8)
  179. This fixed size trigger cannot be touched, it can only be fired by other events.  It can contain killtargets, targets, delays, and messages.
  180. */
  181. void() trigger_relay =
  182. {
  183.     self.use = SUB_UseTargets;
  184. };
  185.  
  186.  
  187. //=============================================================================
  188.  
  189. /*QUAKED trigger_secret (.5 .5 .5) ?
  190. secret counter trigger
  191. sounds
  192. 1)    secret
  193. 2)    beep beep
  194. 3)
  195. 4)
  196. set "message" to text string
  197. */
  198. void() trigger_secret =
  199. {
  200.     total_secrets = total_secrets + 1;
  201.     self.wait = -1;
  202.     if (!self.message)
  203.         self.message = "You found a secret area!";
  204.     if (!self.sounds)
  205.         self.sounds = 1;
  206.     
  207.     if (self.sounds == 1)
  208.     {
  209.         precache_sound ("misc/secret.wav");
  210.         self.noise = "misc/secret.wav";
  211.     }
  212.     else if (self.sounds == 2)
  213.     {
  214.         precache_sound ("misc/talk.wav");
  215.         self.noise = "misc/talk.wav";
  216.     }
  217.  
  218.     trigger_multiple ();
  219. };
  220.  
  221. //=============================================================================
  222.  
  223.  
  224. void() counter_use =
  225. {
  226.     local string junk;
  227.  
  228.     self.count = self.count - 1;
  229.     if (self.count < 0)
  230.         return;
  231.     
  232.     if (self.count != 0)
  233.     {
  234.         if (activator.classname == "player"
  235.         && (self.spawnflags & SPAWNFLAG_NOMESSAGE) == 0)
  236.         {
  237.             if (self.count >= 4)
  238.                 centerprint (activator, "There are more to go...");
  239.             else if (self.count == 3)
  240.                 centerprint (activator, "Only 3 more to go...");
  241.             else if (self.count == 2)
  242.                 centerprint (activator, "Only 2 more to go...");
  243.             else
  244.                 centerprint (activator, "Only 1 more to go...");
  245.         }
  246.         return;
  247.     }
  248.     
  249.     if (activator.classname == "player"
  250.     && (self.spawnflags & SPAWNFLAG_NOMESSAGE) == 0)
  251.         centerprint(activator, "Sequence completed!");
  252.     self.enemy = activator;
  253.     multi_trigger ();
  254. };
  255.  
  256. /*QUAKED trigger_counter (.5 .5 .5) ? nomessage
  257. Acts as an intermediary for an action that takes multiple inputs.
  258.  
  259. If nomessage is not set, t will print "1 more.. " etc when triggered and "sequence complete" when finished.
  260.  
  261. After the counter has been triggered "count" times (default 2), it will fire all of it's targets and remove itself.
  262. */
  263. void() trigger_counter =
  264. {
  265.     self.wait = -1;
  266.     if (!self.count)
  267.         self.count = 2;
  268.  
  269.     self.use = counter_use;
  270. };
  271.  
  272.  
  273. /*
  274. ==============================================================================
  275.  
  276. TELEPORT TRIGGERS
  277.  
  278. ==============================================================================
  279. */
  280.  
  281. float    PLAYER_ONLY    = 1;
  282. float    SILENT = 2;
  283.  
  284. void() play_teleport =
  285. {
  286.     local    float v;
  287.     local    string tmpstr;
  288.  
  289.     v = random() * 5;
  290.     if (v < 1)
  291.         tmpstr = "misc/r_tele1.wav";
  292.     else if (v < 2)
  293.         tmpstr = "misc/r_tele2.wav";
  294.     else if (v < 3)
  295.         tmpstr = "misc/r_tele3.wav";
  296.     else if (v < 4)
  297.         tmpstr = "misc/r_tele4.wav";
  298.     else
  299.         tmpstr = "misc/r_tele5.wav";
  300.  
  301.     sound (self, CHAN_VOICE, tmpstr, 1, ATTN_NORM);
  302.     remove (self);
  303. };
  304.  
  305. void(vector org) spawn_tfog =
  306. {
  307.     s = spawn ();
  308.     s.origin = org;
  309.     s.nextthink = time + 0.2;
  310.     s.think = play_teleport;
  311.  
  312.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  313.     WriteByte (MSG_BROADCAST, TE_TELEPORT);
  314.     WriteCoord (MSG_BROADCAST, org_x);
  315.     WriteCoord (MSG_BROADCAST, org_y);
  316.     WriteCoord (MSG_BROADCAST, org_z);
  317. };
  318.  
  319.  
  320. void() tdeath_touch =
  321. {
  322.     if (other == self.owner)
  323.         return;
  324.  
  325. // frag anyone who teleports in on top of an invincible player
  326.     if (other.classname == "player")
  327.     {
  328.         if (other.invincible_finished > time)
  329.             self.classname = "teledeath2";
  330.         if (self.owner.classname != "player")
  331.         {    // other monsters explode themselves
  332.             T_Damage (self.owner, self, self, 50000);
  333.             return;
  334.         }
  335.         
  336.     }
  337.  
  338.     if (other.health)
  339.     {
  340.         T_Damage (other, self, self, 50000);
  341.     }
  342. };
  343.  
  344.  
  345. void(vector org, entity death_owner) spawn_tdeath =
  346. {
  347. local entity    death;
  348.  
  349.     death = spawn();
  350.     death.classname = "teledeath";
  351.     death.movetype = MOVETYPE_NONE;
  352.     death.solid = SOLID_TRIGGER;
  353.     death.angles = '0 0 0';
  354.     setsize (death, death_owner.mins - '1 1 1', death_owner.maxs + '1 1 1');
  355.     setorigin (death, org);
  356.     death.touch = tdeath_touch;
  357.     death.nextthink = time + 0.2;
  358.     death.think = SUB_Remove;
  359.     death.owner = death_owner;
  360.     
  361.     force_retouch = 2;        // make sure even still objects get hit
  362. };
  363.  
  364. void() teleport_touch =
  365. {
  366. local entity    t;
  367. local vect